package me.landery.modules.sinco.domain;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import me.landery.base.BaseEntity;
import me.landery.modules.system.domain.User;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * @Author cc.w
 * @Date 2022/6/7 19:40
 * @Version 1.0
 */
@Entity
@Getter
@Setter
@Table(name="sinco_call")
public class Call extends BaseEntity implements Serializable {
    @Id
    @Column(name = "cid", nullable = false)
    @NotNull(groups = BaseEntity.Update.class)
    @ApiModelProperty(value = "调用记录ID", hidden = true)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "uid")
    private User user;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "aid")
    private Application application;

    @NotBlank
    @ApiModelProperty(value = "调用类型")
    private String type;

    @NotBlank
    @ApiModelProperty(value = "输入的内容")
    private String content;

    @NotNull
    @ApiModelProperty(value = "返回结果")
    private String result; //额度

    @ApiModelProperty(value = "调用时间")
    private Date time;

    @NotNull
    @ApiModelProperty(value = "是否调用成功")
    private Boolean success;

    @ApiModelProperty(value = "花费金额")
    private Double cost;

    @ApiModelProperty(value = "扣除免费额度")
    private Long quota;

    @ApiModelProperty(value = "调用者ip地址")
    private String ipaddr;

    @ApiModelProperty(value = "调用者位置信息")
    private String addr;

    @ApiModelProperty(value = "文章内容语种")
    private Integer language;

    @ApiModelProperty(value = "文章内容字数")
    private Integer length;

    @Column(name="content_type")
    @ApiModelProperty(value = "文章内容类型，0通用，1金融等")
    private Integer contentType;

    @ApiModelProperty("摘要标题，摘要需要输入的标题")
    private String title;

    @Column(name="generate_type")
    @ApiModelProperty(value = "生成类型，0简洁，1普通，2丰富")
    private Integer generateType;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Call call = (Call) o;
        return Objects.equals(id, call.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
